\frame
{
  \frametitle{Basic approach to writing a detector}
  \begin{enumerate}
	\item Start with a bug (important!)
	\item Write the simplest possible detector that might find similar bugs
	\item Evaluate: does it find enough interesting bugs
              without too many false positives?
        \item Refine: improve analysis and FP suppression heuristics
	\item Repeat steps 3 and 4 until you get something acceptable or
	      you give up on the idea
  \end{enumerate}
}





\frame[containsverbatim]
{
  \frametitle{Don't use String literals for the synchronized blocks! http://www.javalobby.org/java/forums/t96352.html}
Code that is using String literals to synchronize on is dangerous. 

\begin{verbatim}
static private final String LOCK = "LOCK";
void someMethod() {
  synchronized(LOCK) {
    ...
  }}
\end{verbatim}

{\small ...something like this really happened between our code and code in the Jetty library. Both sections used the same string literal above to synchronize critical code sections. The two code segments created a dead-lock with very puzzling stack traces
(The Jetty-Bug has been reported already, btw, Jetty-352).} 
}




\frame[containsverbatim]
{
  \frametitle{ Write  a detector to look for synchronization on constant Strings}
  \B
	\item Add test case
	\item Bytecode:
\begin{verbatim}
LDC "LOCK"
DUP
ASTORE 1
MONITORENTER
\end{verbatim}
	\item Let's use opcode stack.
  \B
         \item Could also look for bytecode sequence.
  \E
  \E
}



\frame[containsverbatim]
{
\frametitle{ SynchronizationOnSharedBuiltinConstant }
{\small
\begin{verbatim}
public void sawOpcode(int seen) {
  if (seen == MONITORENTER) {
    OpcodeStack.Item top = stack.getStackItem(0);
    if (top.getSignature().equals("Ljava/lang/String;") 
        && top.getConstant() instanceof String) 
      bugReporter.reportBug(new BugInstance(this, 
             "DL_SYNCHRONIZATION_ON_SHARED_CONSTANT", 
             NORMAL_PRIORITY)
       .addClassAndMethod(this)
       .addString((String)constant)
       .addSourceLine(this));
  }}
\end{verbatim}
}
}

\frame
{
\frametitle{ Results}
  \B
    \item Found issue fixed in Jetty-352.
    \item Jetty-352 didn't fix all occurrences in Jetty (Jetty-362).
    \item Also found occurrences in Eclipse, glassfish, Sun's JDK, netbeans, nutch, oc4j, weblogic, websphere
    \item Not bad for 20 minutes work
  \E
}

\frame
{
\frametitle{Why simple techniques work}
  \B
  \item We aren't trying to prove anything about the code (other people do that).
  \item Simple mistakes generally result in mistakes that are easy to find.
  \item {\tt javac} does minimal optimization/transformation
  \item Simple analysis produces results that are easy to triage.
  \E
}



